#include <iostream>
#include <string>
#include <cstdlib>

using std::cin;
using std::cout;
using std::endl;
using std::string;

typedef struct Stack {
	char* base;
	char* top;
	int stackSize;
} Stack;

void Poland(string s, int len);
void pop(Stack &s);
void push(Stack &s, char c);
int isEmpty(Stack &s);

int main() {
	int T;// check for T times
	cin >> T;
	for (int t = 0; t < T; t++) {
		int len = 0;
		cin >> len;
		string s;
		cin >> s;
		Poland(s, len);
	}
}

int isEmpty(Stack &s) {
	if (s.top == s.base) return 1;
	else return 0;
}//check the stack is empty or not

void push(Stack &s, char c) {
	s.base = (char*)realloc(s.base,(s.stackSize + 1)*sizeof(char));
	s.top = s.base + s.stackSize;
	s.stackSize++;
	*s.top = c;
	return;
}// push an element into the stack

void pop(Stack &s) {
	cout<<*s.top;
	s.stackSize--;
	s.top--;
	return;
}// pop the top of the stack

void Poland (string str, int len) {
	Stack stack;
	stack.stackSize = 1;
	stack.base = (char*)malloc(stack.stackSize*sizeof(char));
	stack.top = stack.base;
	//Create an empty link stack s
	for (int i = 0; i < len; i++) {
		if (str[i] == '+' || str[i] == '-' ) {//if + or -
			if (*stack.top == '*' || *stack.top == '/' ) {
				pop(stack);
				if (*stack.top == '+' || *stack.top == '-' ) {
					pop(stack);
				}
			}else if (*stack.top == '+' || *stack.top == '-' ) {
					pop(stack);
			}
			push(stack, str[i]);	
		} else if (str[i] == '*' || str[i] == '/' ) {// if * or /
			if (*stack.top == '*' || *stack.top == '/' ) {
				pop(stack);
			}
			push(stack, str[i]); 
		} else {// while it is a variable, output immediately
			cout<<str[i];
		}
	}
	while (isEmpty(stack) == 0){
		pop(stack);
	}//pop the rest of the elements out of the stack
	cout<<"\n";
	return;
}
